package org.duanyu.controller;

import org.springframework.ai.image.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TextToImageController {

    private final ImageModel imageModel;

    public TextToImageController(ImageModel imageModel) {
        this.imageModel = imageModel;
    }

    /**
     * 文生成图
     * @return
     */
    @GetMapping("/image")
    public String image(String message){
        ImageOptions imageModelOptions = ImageOptionsBuilder.builder()
                .withModel("wanx-v1")
                .build();

        //图片提示词
        ImagePrompt imagePrompt = new ImagePrompt(message,imageModelOptions);
        //3.发送请求
        ImageResponse call = imageModel.call(imagePrompt);
        return call.getResult().getOutput().getUrl();
    }
}
